package com.lijian.rest.controller;

import java.awt.PageAttributes.MediaType;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lijian.common.utils.JsonUtils;
import com.lijian.rest.pojo.ItemCatResult;
import com.lijian.rest.service.ItemCatService;

/**
 * <p>Title: ItemCatController.java</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2017</p>
 * @author lijian
 * @date 2017年4月15日上午8:54:44
 * @version 1.0
 */
@Controller
@RequestMapping("/item/cat")
public class ItemCatController {

	@Autowired
	private ItemCatService itemCatService;
	//设置返回类型为json,utf8编码
	@RequestMapping(value="/list",produces=org.springframework.http.MediaType.APPLICATION_JSON_VALUE+";charset=utf-8")
	@ResponseBody
	public String get(@RequestParam(required=false) String callback){
		ItemCatResult itemCatList = itemCatService.getItemCatList();
		String objectToJson = JsonUtils.objectToJson(itemCatList);
		if(StringUtils.isNotEmpty(callback)){
			return callback+"("+objectToJson+");";
		}else{
			return objectToJson;
		}
	}
}
